package com.cartoonrabbit.config.task.monitors;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cartoonrabbit.consts.TransferStatus;
import com.cartoonrabbit.pojo.WithdrawOrder;
import com.cartoonrabbit.service.IWithdrawOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;

import java.io.IOException;
import java.util.List;

/**
 * 转账接口
 */
@Component
public class TransferTask {

    @Autowired
    private IWithdrawOrderService withdrawOrderService;




    /**
     * 每600秒执行一次
     */
    @Scheduled(cron = "50 6/6 * * * *")
    @Transactional
    public void tranferMentNotify() throws IOException {
        // 获取转账中处于失败或进行中的订单
        List<WithdrawOrder> transferList = withdrawOrderService.list(new QueryWrapper<WithdrawOrder>().eq("status", TransferStatus.GOING));
        if (ObjectUtils.isEmpty(transferList)||transferList.size()<=0){
            return;
        }
        for (WithdrawOrder transfer : transferList) {
            withdrawOrderService.checkTransferStatus(transfer);
        }
    }
}
